package com.rj.util;

import com.rj.core.check.SConsumer;
import com.rj.core.check.SPeer;
import com.rj.core.exception.BaseException;
import com.rj.core.exception.ServiceException;

import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Stream;

/**
 * 语法简化工具
 *
 * @author YFX_RANLUBO
 * @date 2024/09/15 20:41
 **/
public class EasyUtils {
    /**
     * 如果为真执行 consumer
     *
     * @param expression
     * @param consumer
     * @param <R>
     * @return
     */
    public static <R> R isTrue(boolean expression, SConsumer<R> consumer) {
        return expression ? consumer.accept() : null;
    }

    /**
     * 如果为真执行 consumer
     *
     * @param expression
     * @param peer
     * @return
     */
    public static void isTrue(boolean expression, SPeer peer) {
        if (expression) {
            peer.accept();
        }
    }

    /**
     * 如果为真执行 consumer
     *
     * @param expression
     * @param trueConsumer
     * @param falseConsumer
     * @param <R>
     * @return
     */
    public static <R> R ifElse(boolean expression, SConsumer<R> trueConsumer, SConsumer<R> falseConsumer) {
        return expression ? trueConsumer.accept() : falseConsumer.accept();
    }
}
